<template>
  <div class="container">
    <img :src="getIcon('icon_password')" style="width: 4vw;margin: 0 0 0 20px">
    <input v-model="password" placeholder="请输入密码" class="input"/>
    <div class="state" v-if="isMatch" v-show="hasInputted">
      <span class="state-text green"></span><img :src="getIcon('true')" class="state-icon">
    </div>
    <div class="state" v-else v-show="hasInputted">
      <span class="state-text main-color">6-16位字母数字组合</span><img :src="getIcon('false')" class="state-icon">
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import Public from '@/assets/js/public';
  import Props from '@/assets/js/Props';

  export default {
    /** kebab-case */
    name: 'cell-password-edit-sx',

    data() {
      return {
        hasInputted: false,
        password: null,
        isMatch: false
      };
    },
    /** 在声明 prop 的时候，其命名应该始终使用 camelCase，而在模板和 JSX 中应该始终使用 kebab-case。
     String/Number/Boolean/Function/Object/Array/Symbol */
    props: {},

    components: {},

    methods: {
      getIcon(icon) {
        return Public.ossImg + icon + '.svg';
      }
    },
    computed: {},
    watch: {
      password() {
        this.hasInputted = true;
        this.isMatch = new RegExp(Props.REGEX_LOGIN_PASSWORD).test(this.password);
        this.$emit('getInput', this.isMatch, this.password);
      }
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  @import "../../assets/stylus/main.styl";
  .flex-r
    flex-x()

  .flex-c
    flex-y()

  .center
    flex-center()

  .divider
    divider()

  .space
    space()

  .container
    flex-x()
    width 100%
    justify-content flex-end
    position relative
    background-color #7F6C6C6C

  .input
    flex 1
    height cell-height
    text-align left
    word-vw(14px,white)
    padding-left 10px
    background-color transparent

  .state
    position absolute
    padding-right 15px
    flex-center()
    justify-content flex-end
    width 45vw
    pointer-events none

  .state-text
    word-vw(12px, main-color)

  .state-icon
    margin-left 1vw
    width 4vw

  .main-color
    color main-color

  .green
    color #00aa00

  ::-webkit-input-placeholder
    word-vw(14px, white)

  :-moz-placeholder
    word-vw(14px, white)

  ::-moz-placeholder
    word-vw(14px, white)

  :-ms-input-placeholder
    word-vw(14px, white)

</style>
